import { Injectable } from "@nestjs/common";
import * as Sequelize from "sequelize";
import sequelize from "../../database/sequelize";

@Injectable()
export class UserExistService {
  async userExist(requestBody: any): Promise<any | undefined> {//每个异步函数都必须返回一个 Promise
    let nickName: string = requestBody.nickName;
    let phoneNum: string = requestBody.phoneNum;
    const sql =
      `SELECT * FROM userRegister WHERE nickName = '${nickName}' or phoneNum = '${phoneNum}'`;
    try {
      let userList = (await sequelize.query(sql, {
        type: Sequelize.QueryTypes.SELECT,
        raw: true,
        logging: false
      }));
      return userList[0];
    } catch (error) {
      console.error(error);
      return void 0;//void相当于函数兜底，但此处作用不鲜明
    }
  }
}
